<template>
	<view class="category">
		<view class="nav">
			<uv-tabs lineHeight="0" :activeStyle="{
				color: '#303133',
				 fontSize: '56rpx'}" :inactiveStyle="{
				     fontSize: '36rpx' 
				   }" :list="list" @click="click">
			</uv-tabs>
		</view>
		<view class="space"></view>
		<!-- tab栏 -->
		<view class="cat_tab">
			<view 
			        v-for="(tab, index) in tabs" 
			        :key="index"
			        :class="['tab-btn', currentTab === index ? 'active' : '']"
			        @click="switchTab(index)"
			      >
			        {{ tab }}
			      </view>
		</view>
		<view class="cat">
			<view class="category-page">
				<!-- 按题材分类 -->
				<text class="section-title">—— 按题材分类 ——</text>
				<view class="category-section">
					<view class="category-grid">
						<view class="category-item" v-for="(item, index) in themeCategories" :key="index"
							@click="handleCategoryClick(item)">
							<view class="icon-circle">
								<image class="icon" :src="item.icon" mode="aspectFit" />
							</view>
							<text class="category-name">{{item.name}}</text>
						</view>
					</view>
				</view>

				<!-- 按情节分类 -->
				<text class="section-title">—— 按情节分类 ——</text>
				<view class="category-section">
					<view class="category-grid">
						<view class="category-item" v-for="(item, index) in plotCategories" :key="index"
							@click="handleCategoryClick(item)">
							<view class="icon-circle">
								<image class="icon" :src="item.icon" mode="aspectFit" />
							</view>
							<text class="category-name">{{item.name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentTab: 0, // 默认选中第一个标签
				tabs: ['题材', '情节', '角色', '风格'],
				list: [{
					name: '男生'
				}, {
					name: '女生'
				}],
				// 按题材分类
				themeCategories: [{
						name: '都市',
						icon: '/static/images/category/dushi.png',
						color: '#4A90E2',
						type: 'theme'
					},
					{
						name: '体育',
						icon: '/static/images/category/tiyu.png',
						color: '#7ED321',
						type: 'theme'
					},
					{
						name: '影视',
						icon: '/static/images/category/yingshi.png',
						color: '#F8E71C',
						type: 'theme'
					},
					{
						name: '乡村',
						icon: '/static/images/category/xiangcun.png',
						color: '#417505',
						type: 'theme'
					}, {
						name: '都市',
						icon: '/static/images/category/dushi.png',
						color: '#4A90E2',
						type: 'theme'
					},
					{
						name: '体育',
						icon: '/static/images/category/tiyu.png',
						color: '#7ED321',
						type: 'theme'
					},
					{
						name: '影视',
						icon: '/static/images/category/yingshi.png',
						color: '#F8E71C',
						type: 'theme'
					},
					{
						name: '乡村',
						icon: '/static/images/category/xiangcun.png',
						color: '#417505',
						type: 'theme'
					}
				],
				// 按情节分类
				plotCategories: [{
						name: '都市',
						icon: '/static/images/category/dushi.png',
						color: '#4A90E2',
						type: 'theme'
					},
					{
						name: '体育',
						icon: '/static/images/category/tiyu.png',
						color: '#7ED321',
						type: 'theme'
					},
					{
						name: '影视',
						icon: '/static/images/category/yingshi.png',
						color: '#F8E71C',
						type: 'theme'
					},
					{
						name: '乡村',
						icon: '/static/images/category/xiangcun.png',
						color: '#417505',
						type: 'theme'
					}, {
						name: '都市',
						icon: '/static/images/category/dushi.png',
						color: '#4A90E2',
						type: 'theme'
					},
					{
						name: '体育',
						icon: '/static/images/category/tiyu.png',
						color: '#7ED321',
						type: 'theme'
					},
					{
						name: '影视',
						icon: '/static/images/category/yingshi.png',
						color: '#F8E71C',
						type: 'theme'
					},
					{
						name: '乡村',
						icon: '/static/images/category/xiangcun.png',
						color: '#417505',
						type: 'theme'
					}
				]
			}
		},
		methods: {
			click() {

			},
			handleCategoryClick(item) {
				uni.navigateTo({
					url: `/pages/category/filterView?type=${item.type}&category=${item.name}`
				})
			},
			switchTab(index) {
				this.currentTab = index;
				// 这里可以添加加载对应分类数据的逻辑
			}
		}
	}
</script>

<style lang="scss" scoped>
	.category {
		background-color: #f6f8fa;
	}

	.nav {
		border-width: 0px;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		background-color: #FFFFFF;
		padding: 0 20px;
		width: 375px;
		height: 49px;
		display: flex;
	}

	.space {
		height: 60px;
	}

	.cat_tab {
		display: flex;
		justify-content: center;
		gap: 20rpx;
		/* 按钮间距 */
		margin-bottom: 40rpx;

		.tab-btn {
			padding: 16rpx 32rpx;
			border-radius: 40rpx;
			/* 椭圆形 */
			background-color: #f0f0f0;
			/* 默认灰色 */
			color: #333333;
			font-size: 28rpx;
			transition: all 0.3s;
			border: none;

			/* 选中状态 - 完全匹配图片中的蓝色按钮 */
			&.active {
				background-color: #02a7f0;
				/* 亮蓝色 */
				color: #ffffff;
				/* 白色文字 */
				/* 添加轻微阴影提升质感 */
				box-shadow: 0 2rpx 8rpx rgba(2, 167, 240, 0.3);
			}
		}
	}

	.category-page {
		background-color: #f7f7f7;
		min-height: 100vh;
	}

	.category-section {
		background-color: #ffffff;
		padding: 30rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
	}

	.section-title {
		display: block;
		text-align: center;
		font-size: 32rpx;
		color: #333;
		margin-bottom: 40rpx;
		position: relative;
	}

	.category-grid {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 10rpx;
		/* 添加内边距 */
	}

	.category-item {
		width: 25%;
		/* 四个一行，每个占25%宽度 */
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 30rpx;
		padding: 10rpx;
		/* 添加内边距 */
		box-sizing: border-box;
		/* 确保padding不影响宽度 */
	}

	.icon-circle {
		width: 120rpx;
		/* 增大容器宽度 */
		height: 120rpx;
		/* 增大容器高度 */
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 16rpx;

		image {
			width: 120rpx;
			height: 120rpx;
		}
	}

	.icon {
		width: 80rpx;
		/* 增大图标宽度 */
		height: 80rpx;
		/* 增大图标高度 */
	}

	.category-name {
		font-size: 26rpx;
		/* 稍微减小字体大小 */
		color: #333;
		text-align: center;
		margin-top: 10rpx;
		width: 100%;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		/* 文字超出显示省略号 */
	}
</style>